package com.macro.mall.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.model.TitleRes;

import com.macro.mall.model.PmsTitle;
import com.macro.mall.service.TitleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class TitleController {
    @Autowired
    private TitleService service;

    /**
     * 商品标签列表
     */
    @GetMapping("/titleList/{cid}")
    public CommonResult<PageInfo<PmsTitle>> titleList(@PathVariable Integer cid) {
        TitleRes  titleRes = new TitleRes();
        PageHelper.startPage(titleRes.getPageNum(), titleRes.getPageSize());
        List<PmsTitle> list = service.titleList(cid);
        PageInfo<PmsTitle> pageInfo = new PageInfo<>(list);
        return CommonResult.success(pageInfo);
    }
    /**
     * 添加
     */
    @PostMapping("/addTitle")
    public CommonResult<PmsTitle> addTitle(@RequestBody PmsTitle title) {
        Integer cid = title.getCid();
        title.setTypeId(cid);
        service.addTitle(title);
        return CommonResult.success(null);
    }
    /**
     * 修改
     */
    @PostMapping("/updTitle")
    public CommonResult<PmsTitle> updTitle(@RequestBody PmsTitle title) {
         service.updTitle(title);
         return CommonResult.success(null);
    }

    /**
     * 删除
     */
    @PostMapping("/del/{ids}")
    public CommonResult<PmsTitle> del(@PathVariable Integer ids) {
         service.del(ids);
         return CommonResult.success(null);
    }
    /**
     * 回显
     */
    @GetMapping("/byid/{id}")
    public CommonResult<PmsTitle> byid(@PathVariable Integer id) {
        PmsTitle title = service.byid(id);
        return CommonResult.success(title);
    }
}
